From: Florian Müllner Date: Mon, 18 Feb 2013 20:35:02 +0000 (+0100) Subject: messageTray: Move makeCloseButton() into Util X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~4741 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=f21b8206afb615b670b3c9254395b5c3ae24bc53;p=gnome-shell.git messageTray: Move makeCloseButton() into Util The function is useful for other modules as well, so move it to a more generic place. https://bugzilla.gnome.org/show_bug.cgi?id=694192 --- diff --git a/js/misc/util.js b/js/misc/util.js index 98c231030..d0ea7ca3f 100644 --- a/js/misc/util.js +++ b/js/misc/util.js @@ -1,6 +1,8 @@ // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- +const Clutter = imports.gi.Clutter; const GLib = imports.gi.GLib; +const St = imports.gi.St; const Main = imports.ui.main; @@ -208,3 +210,27 @@ function insertSorted(array, val, cmp) { return pos; } + +function makeCloseButton() { + let closeButton = new St.Button({ style_class: 'notification-close'}); + + // This is a bit tricky. St.Bin has its own x-align/y-align properties + // that compete with Clutter's properties. This should be fixed for + // Clutter 2.0. Since St.Bin doesn't define its own setters, the + // setters are a workaround to get Clutter's version. + closeButton.set_x_align(Clutter.ActorAlign.END); + closeButton.set_y_align(Clutter.ActorAlign.START); + + // XXX Clutter 2.0 workaround: ClutterBinLayout needs expand + // to respect the alignments. + closeButton.set_x_expand(true); + closeButton.set_y_expand(true); + + closeButton.connect('style-changed', function() { + let themeNode = closeButton.get_theme_node(); + closeButton.translation_x = themeNode.get_length('-shell-close-overlap-x'); + closeButton.translation_y = themeNode.get_length('-shell-close-overlap-y'); + }); + + return closeButton; +} diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index dc182d897..308b223e8 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -220,30 +220,6 @@ const URLHighlighter = new Lang.Class({ } }); -function makeCloseButton() { - let closeButton = new St.Button({ style_class: 'notification-close'}); - - // This is a bit tricky. St.Bin has its own x-align/y-align properties - // that compete with Clutter's properties. This should be fixed for - // Clutter 2.0. Since St.Bin doesn't define its own setters, the - // setters are a workaround to get Clutter's version. - closeButton.set_x_align(Clutter.ActorAlign.END); - closeButton.set_y_align(Clutter.ActorAlign.START); - - // XXX Clutter 2.0 workaround: ClutterBinLayout needs expand - // to respect the alignments. - closeButton.set_x_expand(true); - closeButton.set_y_expand(true); - - closeButton.connect('style-changed', function() { - let themeNode = closeButton.get_theme_node(); - closeButton.translation_x = themeNode.get_length('-shell-close-overlap-x'); - closeButton.translation_y = themeNode.get_length('-shell-close-overlap-y'); - }); - - return closeButton; -} - function strHasSuffix(string, suffix) { return string.substr(-suffix.length) == suffix; } @@ -1383,7 +1359,7 @@ const SummaryItem = new Lang.Class({ this.notificationStackView.add_actor(this.notificationStack); this.notificationStackWidget.add_actor(this.notificationStackView); - this.closeButton = makeCloseButton(); + this.closeButton = Util.makeCloseButton(); this.notificationStackWidget.add_actor(this.closeButton); this._stackedNotifications = []; @@ -1638,7 +1614,7 @@ const MessageTray = new Lang.Class({ this._clickedSummaryItemMouseButton = -1; this._clickedSummaryItemAllocationChangedId = 0; - this._closeButton = makeCloseButton(); + this._closeButton = Util.makeCloseButton(); this._closeButton.hide(); this._closeButton.connect('clicked', Lang.bind(this, this._closeNotification)); this._notificationWidget.add_actor(this._closeButton);